﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ad_positionmanage.aspx.cs" Inherits="backmanage_adsystem_ad_positionmanage" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>广告位管理</title>
    <script type="text/javascript" src="../js/jquery-1.6.1.js"></script>
	<link rel="stylesheet" href="../css/jquery.ui.all.css" />
	<script type="text/javascript" src="../external/jquery.bgiframe-2.1.2.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.core.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.widget.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.mouse.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.button.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.draggable.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.position.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.resizable.js"></script> 
	<script type="text/javascript" src="../js/jquery.ui.dialog.js"></script> 
	<script type="text/javascript" src="../js/jquery.effects.core.js"></script>
	<link rel="stylesheet" href="../css/demos.css" />  
    <script type="text/javascript">
    $(function(){
               function AdpositionAdd()
               {
                  var title=$("#title").val();
                  var page=$("#page").val();
                  var width=$("#width").val();
                  var height=$("#height").val();
                  var state;
                  var c=$("#create-form input:checked");
                  if(c.length>0)
                  {
                       state=1;
                  }
                  else
                  {
                       state=0;
                  }
                  $.ajax({
                          async:false,
                          url:'../API/A_Adposition.aspx',
                          type:'POST',
                          data:{
                                edit:'add',
                                t:title,
                                p:page, 
                                w:width,
                                h:height,
                                s:state,
                               },
                           success:function(msg)
                           {
                              //alert(msg);
                           }
                  });
               }
               function AdpositionEdit(i)
               {
                  var t=$("#"+i+" a.title").text();
                  var p=$("#"+i+" a.page").text();
                  var w=$("#"+i+" span.width").text();
                  var h=$("#"+i+" span.height").text();
                  var s=$("#"+i+" a.state").text();
                  $("#title").val(t);
                  $("#page").val(p);
                  $("#width").val(w);
                  $("#height").val(h);
                  if(s=="true")
                  {
                    $("#create-form input:checkbox").attr("checked",true);
                  }
                  else
                  {
                    $("#create-form input:checkbox").removeAttr("checked");
                  }
               }
               function AdpositionUpdate(id)
               {
                  var title=$("#title").val();
                  var page=$("#page").val();
                  var width=$("#width").val();
                  var height=$("#height").val();
                  var state;
                  var c=$("#create-form input:checked");
                  if(c.length>0)
                  {
                       state=1;
                  }
                  else
                  {
                       state=0;
                  }
                  $.ajax({
                          async:false,
                          url:'../API/A_Adposition.aspx',
                          type:'POST',
                          data:{
                                edit:'update',
                                id:id,
                                t:title,
                                p:page,
                                w:width,
                                h:height,
                                s:state,
                          },
                          success:function(msg)
                          {
                             //alert(msg);
                          }
                  });
               }
               function AdpositionUpdateState(id)
               {
                  var state=$("#"+id+" a.state").text();
                  $.ajax({
                          async:false,
                          url:'../API/A_Adposition.aspx',
                          type:'POST',
                          data:{
                                edit:'state',
                                id:id,
                                s:state,
                          },
                          success:function(msg)
                          {
                             //alert(msg);
                          }
                  });
               }
               function AdpositionList()
               {
                  $.ajax({
                         async:true,
                         url:'../API/A_Adposition.aspx',
                         type:'POST',
                         data:{edit:'list'},
                         success:function(msg)
                         {
                            $("#positionlist tbody").text("");
                            $("#positionlist tbody").append(msg);
                            $("table [title$='edit']").click(function(){
                                  var i=$(this).parent().parent().attr("id");
                                  SetEditWindows(i);
                                  $("#create-form").dialog("open");
                                  AdpositionEdit(i);
                               });
                            $("table [title$='state']").click(function(){
                                  var i=$(this).parent().parent().attr("id");
                                  SetStateWindows(i);
                                  $("#windows-info").dialog("open");
                            });
                         }
                  });
               }
               function del()
               {
                 var c=$("#positionlist input:checked");
                    var b=new Array();
                    for(var i=0;i<c.length;i++)
                    {
                      b[i]=c[i].value;
                    }
                    if(b.length>0)
                    {
                      $.ajax({
                             async:false,
                             url:'../API/A_Adposition.aspx',
                             type:'POST',
                             data:{edit:'del',id:b},
                             success:function(msg)
                             {
                                AdpositionList();
                                //alert(msg);
                             }
                      });
                    }
                    else
                    {
                       alert("请先选择.");
                    }
               }
               function allyes()
               {
                 $("#positionlist input:checkbox").attr("checked",true);
               }
               function allno()
               {
                 $("#positionlist input:checkbox").removeAttr("checked");
               }
               $("#create-form").dialog("destory");
               $("#windows-info").dialog("destory");
               function SetAddWindows()
               {
               $("#create-form").dialog({
                        autoOpen:false,
                        height:270,
                        width:170,
                        modal:true,
                        resizable:false,
                        buttons:{
                                 "提交":function(){
                                       AdpositionAdd();
                                       $(this).dialog("close");
                                       AdpositionList();
                                 },
                                 "取消":function(){$(this).dialog("close");},
                                 },
               });
               }
               function SetStateWindows(id)
               {
               $("#windows-info").dialog({
                          autoOpen:false,
                          height:130,
                          width:230,
                          modal:true,
                          resizable:false,
                          buttons:{
                                  "确定":function(){
                                       AdpositionUpdateState(id);
                                       $(this).dialog("close");
                                       AdpositionList();
                                  },
                                  "取消":function(){
                                       $(this).dialog("close");
                                  },
                          },
               });
               }
               function SetEditWindows(id)
               {
               $("#create-form").dialog({
                        autoOpen:false,
                        height:270,
                        width:170,
                        modal:true,
                        resizable:false,
                        buttons:{
                                 "修改":function(){
                                       $(this).dialog("close");
                                       AdpositionUpdate(id);
                                       AdpositionList();
                                 },
                                 "取消":function(){$(this).dialog("close");},
                                 },
               });
               }
               $("#create-user").button().click(function(){
                  SetAddWindows();
                  $("#create-form input:text").val("");
                  $("#create-form").dialog("open");
               });
               $("#del").click(function(){del();});
               $("#allyes").click(function(){allyes();});
               $("#allno").click(function(){allno();});
               $(document).ready(function(){AdpositionList();});
    })
    </script>
    <style type="text/css">
    .create-form{ display:none;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    广告位管理<a id="create-user">添加广告位</a>
    <table id="positionlist">
      <thead>
        <tr>
          <td>操作</td>
          <td>描述</td>
          <td>所在页面</td>
          <td>大小</td>
          <td>状态</td>
          <td>编辑</td>
        </tr>
      </thead>
      <tbody>
      
      </tbody>
      <tfoot>
         <tr>
           <td colspan="10">一共0条 10条/页<input type="button" id="del" value="删除" /><input type="button" id="allyes" value="全选" /><input type="button" id="allno" value="全不选" /></td>
         </tr>
      </tfoot>
    </table>
    </div>
    <div id="create-form" class="create-form" title="添加广告位">
    描述：<input type="text" id="title" />
    所在页面：<input type="text" id="page" />
    宽：<input type="text" id="width" />
    高：<input type="text" id="height" />
    是否可用：<input type="checkbox" id="state" />
    </div>
    <div id="windows-info" class="create-form" title="系统提示">
    <p>确定要修改广告位的可用状态？</p>
    </div>
    </form>
</body>
</html>
